home *** CD-ROM | disk | FTP | other *** search
/ Family Forum 262 / SOMC Family Forum 262.iso / Xtras / Widget Wizard / Widget Wizard.dir / WidgtBehaviors_53_horiz slider.ls < prev    next >
Encoding:
Text File  |  1997-05-10  |  6.0 KB  |  153 lines

  1. property horizontal, extentSprite, hiliteMember, tracking, newLocH, newLocV, sending, dynamic, style, Addressee, name, notify_list, min, max, valrange, minScreen, maxScreen, currentScreenVal, extentlength
  2.  
  3. on getPropertyDescriptionList
  4.   set description to [:]
  5.   if the currentSpriteNum = 0 then
  6.     set memdefault to 0
  7.     set leftOfExtent to 0
  8.     set rightofExtent to 0
  9.   else
  10.     set memref to the member of sprite the currentSpriteNum
  11.     set castLibNum to the castLibNum of memref
  12.     set memdefault to member (the memberNum of member memref + 1) of castLib castLibNum
  13.     set HextentSprite to the currentSpriteNum - 1
  14.     set leftOfExtent to the left of sprite HextentSprite
  15.     set rightofExtent to the right of sprite HextentSprite
  16.   end if
  17.   addProp(description, #hiliteMember, [#default: memdefault, #format: #bitmap, #comment: "Pict for Down:"])
  18.   addProp(description, #dynamic, [#default: 1, #format: #boolean, #comment: "Dynamic:"])
  19.   addProp(description, #name, [#default: "Horizontal", #format: #string, #comment: "Slider Name:"])
  20.   addProp(description, #extentSprite, [#default: the currentSpriteNum - 1, #format: #integer, #comment: "Extent Sprite:"])
  21.   addProp(description, #min, [#default: leftOfExtent, #format: #float, #comment: "Minimum:"])
  22.   addProp(description, #max, [#default: rightofExtent, #format: #float, #comment: "Maximum:"])
  23.   addProp(description, #horizontal, [#default: 1, #format: #boolean, #comment: "Horizontal (if not vertical):"])
  24.   return description
  25. end
  26.  
  27. on getBehaviorDescription
  28.   return "Enables a custom slider.  The slider handle is constrained to an 'extent' sprite.  Slider sends values as a parameter of an event (SliderSet slider_name, value)." & RETURN & "PARAMETERS:" & RETURN & "ΓÇó Pict for Down - member to represent handle while sliding." & RETURN & "ΓÇó Dynamic - if true value is sent while sliding, else value is sent when the handle is released." & RETURN & "ΓÇó Slider Name - name of slider sent along with value." & RETURN & "ΓÇó Minimum - least value slider can be set to." & RETURN & "ΓÇó Maximum - greatest value slider can be set to." & RETURN & "ΓÇó Extent Sprite - the channel number of the rect that constrains the handle." & RETURN & "ΓÇó Horizontal - Orientation of slider, can be horizontal os vertical."
  29. end
  30.  
  31. on getAssocMembers
  32.   set myPropList to [hiliteMember]
  33.   return myPropList
  34. end
  35.  
  36. on compute_val me
  37.   set val to 0.0
  38.   set val to float(the currentScreenVal of me) / float(the extentlength of me)
  39.   set val to val * the valrange of me
  40.   set val to val + the min of me
  41.   return val
  42. end
  43.  
  44. on send_the_val me, val
  45.   case the style of me of
  46.     #sendAllSprites:
  47.       sendAllSprites(#slider_set, the name of me, val)
  48.     #sendSprite:
  49.       repeat with s in the notifyList of me
  50.         sendSprite(s, #slider_set, the name of me, val)
  51.       end repeat
  52.     #call:
  53.       call(#slider_set, the notifyList of me, the name of me, val)
  54.   end case
  55. end
  56.  
  57. on beginSprite me
  58.   set the style of me to #sendAllSprites
  59.   set the sending of me to 1
  60.   set handle to the spriteNum of me
  61.   set the tracking of me to 0
  62.   set the newLocH of me to the locH of sprite handle
  63.   set the newLocV of me to the locV of sprite handle
  64.   if the horizontal of me then
  65.     set the newLocV of me to the locV of sprite the extentSprite of me
  66.     set the minScreen of me to the left of sprite the extentSprite of me
  67.     set the maxScreen of me to the right of sprite the extentSprite of me
  68.   else
  69.     set the newLocH of me to the locH of sprite the extentSprite of me
  70.     set the minScreen of me to the top of sprite the extentSprite of me
  71.     set the maxScreen of me to the bottom of sprite the extentSprite of me
  72.   end if
  73.   set the locH of sprite handle to the newLocH of me
  74.   set the locV of sprite handle to the newLocV of me
  75.   set the valrange of me to the max of me - the min of me
  76.   set the extentlength of me to the maxScreen of me - the minScreen of me
  77.   if the sending of me = 0 then
  78.     set the dynamic of me to 0
  79.   end if
  80. end
  81.  
  82. on endSprite me
  83. end
  84.  
  85. on prepareFrame me
  86.   if tracking then
  87.     set handle to the spriteNum of me
  88.     set extent to the extentSprite of me
  89.     if the horizontal of me then
  90.       set the newLocH of me to the mouseH
  91.       set the newLocV of me to the locV of sprite extent
  92.       if the newLocH of me < the left of sprite extent then
  93.         set the newLocH of me to the left of sprite extent
  94.       end if
  95.       if the newLocH of me > the right of sprite extent then
  96.         set the newLocH of me to the right of sprite extent
  97.       end if
  98.       set the currentScreenVal of me to the newLocH of me - the minScreen of me
  99.     else
  100.       set the newLocH of me to the locH of sprite extent
  101.       set the newLocV of me to the mouseV
  102.       if the newLocV of me < the top of sprite extent then
  103.         set the newLocV of me to the top of sprite extent
  104.       end if
  105.       if the newLocV of me > the bottom of sprite extent then
  106.         set the newLocV of me to the bottom of sprite extent
  107.       end if
  108.       set the currentScreenVal of me to the newLocV of me - the minScreen of me
  109.     end if
  110.     set the locH of sprite handle to the newLocH of me
  111.     set the locV of sprite handle to the newLocV of me
  112.     if the dynamic of me then
  113.       set x to compute_val(me)
  114.       send_the_val(me, x)
  115.     end if
  116.   end if
  117. end
  118.  
  119. on mouseDown me
  120.   set tracking to 1
  121.   set temp to the member of sprite the spriteNum of me
  122.   set the member of sprite the spriteNum of me to member the hiliteMember of me
  123.   set the hiliteMember of me to temp
  124. end
  125.  
  126. on mouseUp me
  127.   set tracking to 0
  128.   set temp to the member of sprite the spriteNum of me
  129.   set the member of sprite the spriteNum of me to member the hiliteMember of me
  130.   set the hiliteMember of me to temp
  131.   if the sending of me then
  132.     set x to compute_val(me)
  133.     send_the_val(me, x)
  134.   end if
  135. end
  136.  
  137. on mouseUpOutSide me
  138.   set tracking to 0
  139.   set temp to the member of sprite the spriteNum of me
  140.   set the member of sprite the spriteNum of me to member the hiliteMember of me
  141.   set the hiliteMember of me to temp
  142.   if the sending of me then
  143.     set x to compute_val(me)
  144.     send_the_val(me, x)
  145.   end if
  146. end
  147.  
  148. on mouseEnter me
  149. end
  150.  
  151. on mouseLeave me
  152. end
  153.